package com.youlu.campus.admin.auth.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.collect.Lists;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;

import java.util.List;

/**
 * Created by zhuhuaiqi
 */
@Data
@NoArgsConstructor
public class Menu {

    private String id;

    private String name;

    @JsonProperty("route")
    private String url;

    private String img;

    private String imgActive;

    @JsonIgnore
    private Integer weight;

    private Long parentId;

    @JsonProperty("childs")
    private List<Menu> childs;


    public Menu(String id, String name, String url, String img, String imgActive) {
        this.id = id;
        this.name = name;
        this.url = url;
        this.img = img;
        this.imgActive = imgActive;
    }

    public String getUrl() {
        return StringUtils.stripToEmpty(url);
    }

    public String getImg() {
        return StringUtils.stripToEmpty(img);
    }

    public String getImgActive() {
        return StringUtils.stripToEmpty(imgActive);
    }

    public List<Menu> getChilds() {
        if (CollectionUtils.isEmpty(childs)) {
            childs = Lists.newArrayList();
        }
        return childs;
    }
}
